package com.lijin.dao;

import com.lijin.domain.entity.Lottery;
import java.util.List;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * Created by gold-jx on 2017/5/27.
 */
public interface LotteryDao {

  String BASE_RESULT = "lottery_result";

  String TABLE_NAME = "lottery";

  String COLUMNS = "lottery_name, lottery_code, lottery_speed, lottery_url, create_time, modify_time, state,level, source";

  @Insert("INSERT INTO " + TABLE_NAME + " (" + COLUMNS + ") VALUES (" +
      "#{lotteryName},#{lotteryCode},#{lotterySpeed},#{lotteryUrl},now() ,now() ,#{state} ,#{level} ,#{source})")
  public int insertLottery(Lottery lottery);


  /**
   * 根据彩种删除
   */
  @Update("UPDATE lottery SET state='DELETE' WHERE lottery_code=#{code}")
  public void deleteLottery(String code);


  /**
   * 根据彩种查询可用url
   */
  @Select("SELECT * FROM lottery WHERE  lottery_code = #{code} and state='NORMAL' ORDER BY level desc")
  @ResultMap(BASE_RESULT)
  List<Lottery> findByCode(String code);


  /**
   * 查询所有可用彩种
   */
  @Select("SELECT * FROM lottery  where state='NORMAL' ")
  @Results(
      id = BASE_RESULT,
      value = {
          @Result(column = "lottery_name", property = "lotteryName"),
          @Result(column = "lottery_code", property = "lotteryCode"),
          @Result(column = "lottery_speed", property = "lotterySpeed"),
          @Result(column = "lottery_url", property = "lotteryUrl"),
          @Result(column = "create_time", property = "createTime"),
          @Result(column = "modify_time", property = "modifyTime"),
          @Result(column = "level", property = "level"),
          @Result(column = "source", property = "source")
      })
  List<Lottery> findAll();


}
